package org.example.config;

import org.example.consumer.LocalKafkaConsumer;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 目前没用上 备用
 * @author youshang
 * @date 2021/02/18 13:29
 **/
public class LocalThreadPoolExecutor {

    public static void execute(LocalKafkaTemplate kafkaTemplate){
        ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 10, 200, TimeUnit.MILLISECONDS,
                new ArrayBlockingQueue<Runnable>(5));

        try {
//            LocalKafkaConsumer localKafkaConsumer = new LocalKafkaConsumer(kafkaTemplate);
//            executor.execute(localKafkaConsumer);
        }catch (Exception e){
//            executor.shutdown(); //即便报错也不停止当前线程
            e.printStackTrace();
        }
        System.out.println("线程池中线程数目：" + executor.getPoolSize() + "，队列中等待执行的任务数目：" +
                executor.getQueue().size() + "，已执行玩别的任务数目：" + executor.getCompletedTaskCount());
    }
}
